package com.zd.kids.ui.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.hyy.libray.presenter.IBasePresenter;
import com.hyy.libray.ui.activity.BaseActivity;
import com.zd.kids.DataBean.UseGuideDataBean;
import com.zd.kids.R;
import com.zd.kids.net.CustomObserver;
import com.zd.kids.net.HttpMethod;
import com.zd.kids.ui.adapter.UseGuideAdapter;

import java.util.ArrayList;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;

public class UseGuideActivity extends BaseActivity {


    @BindView(R.id.view_statusbar)
    View mViewStatusbar;
    @BindView(R.id.img_back)
    ImageView mImgBack;
    @BindView(R.id.img_top)
    ImageView mImgTop;
    @BindView(R.id.ll_all_video)
    LinearLayout mLlAllVideo;
    @BindView(R.id.ll_bottom_root)
    LinearLayout mLlBottomRoot;
    @BindView(R.id.recycle_view)
    RecyclerView recyclerView;
    @BindView(R.id.img_top_flag)
    ImageView imgTopFlag;

    /**
     * 获取布局文件地址
     */
    @Override
    public int getLayoutResId() {
        return R.layout.activity_use_guide;
    }

    UseGuideAdapter useGuideAdapter;

    String groupId;
    String groupPosition;

    /**
     * 初始化布局
     */
    @Override
    public void initView() {


        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) mViewStatusbar.getLayoutParams();
        layoutParams.height = ImmersionBar.getStatusBarHeight(this);
        mViewStatusbar.setLayoutParams(layoutParams);

        ImmersionBar.with(this)
                .fullScreen(true)
                .hideBar(BarHide.FLAG_HIDE_BAR)
                .init();
        groupId = getIntent().getStringExtra("groupId");
        groupPosition = getIntent().getStringExtra("groupPosition");
        useGuideAdapter = new UseGuideAdapter(new ArrayList<>(), groupPosition);

        if ("0".equals(groupPosition)) {
            imgTopFlag.setImageResource(R.mipmap.ic_use_guide_blue_top);
        } else if ("1".equals(groupPosition)) {
            imgTopFlag.setImageResource(R.mipmap.ic_use_yellow_top);
        } else if ("2".equals(groupPosition)) {
            imgTopFlag.setImageResource(R.mipmap.ic_use_guide_green_top);
        }

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(useGuideAdapter);

        HttpMethod.getIntence().getVideoGuide(groupId, new CustomObserver<UseGuideDataBean>() {
            @Override
            public void onSuccess(UseGuideDataBean useGuideDataBean) {

                mAllVideoPath = useGuideDataBean.getComplex_video();
                if (useGuideDataBean.getList() != null) {
                    useGuideAdapter.setNewData(useGuideDataBean.getList());
                }
            }

            @Override
            public void onError(String errorCode) {

            }
        });
    }

    String mAllVideoPath;

    /**
     * 获取Presenter，不用MVP，可以为空
     *
     * @return
     */
    @Override
    protected IBasePresenter onBasePresenter() {
        return null;
    }

    @OnClick({R.id.img_back, R.id.ll_all_video, R.id.tv_help})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.ll_all_video:
                intent = new Intent(this, VideoRecordActivity.class);
                intent.putExtra("VIDEO_PATH", mAllVideoPath);
                startActivity(intent);
                break;
            case R.id.tv_help:
                intent = new Intent(this, HelpActivity.class);
                startActivity(intent);
                break;
        }
    }
}